<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 幕小铺科技（大连）有限公司 [ http://www.XXX.com ]
// +----------------------------------------------------------------------
// | 2020/03/14 jason wang
// +----------------------------------------------------------------------
namespace app\erp\logic;
use think\facade\Hook;
use think\DB;
use util\Tree;
use think\facade\Debug;
use think\facade\Cache;
class Goodslogic{

    /**
     * 添加
     * @param  int    $user_id   操作用户ID
     * @author jason
     * @return mixed
     */
    public function goods_list($user_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' 	            => $user_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $list = model('ErpGoods') -> paginate();//dump($list);
            $rel_list = [];
            foreach ($list as $key => $value) {
                $rel = $this -> getGoodsInfo($value['id']);//dump($rel);
                if($rel['code'] == 200){
                    $rel_list[] = $rel['data'];
                }
            }
            //dump($rel_list);

            $result_list = [];
			$result_list['total']  			= (int)$list -> total();//总数
            $result_list['current_page']	= (int)$list -> currentPage();//页码
            $result_list['last_page']   	= (int)$list -> lastPage();//总页数
            $result_list['per_page']   		= (int)$list -> listRows();//每页条数
            $result_list['data'] 			= $rel_list;
            
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $result_list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }

    /**
     * 添加
     * @param  int    $user_id   操作用户ID
     * @author jason
     * @return mixed
     */
    public function getGoodsInfo($goods_id, $store_id = 0){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'goods_id' 	            => $goods_id,
                'store_id' 	            => $store_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/
            
            /********业务逻辑********/
            $info = model('erp/ErpGoods')->useGlobalScope(false)  ->cache(true)  -> find($goods_id);//dump(isset($info->get_erp_goods_brand));die;
            
            if(!$info){
                DB::rollback();
                return array_out(-1002, '商品不存在');//前置错误 -1002
            }

            //缩略图
            $coverlist = controller('erp/GoodsCoverimglogic', 'logic') -> getCoverImgListByGoodsid($goods_id);//dump($params);
            if($coverlist['code'] == 200) $coverlistimgArr = $coverlist['data'];
            //详情图
            $detailslist = controller('erp/GoodsDetailslogic', 'logic') -> getListByGoodsid($goods_id);//dump($params);
            if($detailslist['code'] == 200) $detailsImgArr = $detailslist['data'];
            //商品参数
            $parameterInfo = controller('erp/GoodsParameterlogic', 'logic') -> getListByGoodsid($goods_id);//dump($parameterInfo);
            if($parameterInfo['code'] == 200) $parameterArr = $parameterInfo['data'];
            //商品规格
            $specificationsInfo = controller('erp/GoodsSpecificationslogic', 'logic') -> getListByGoodsid($goods_id);
            if($specificationsInfo['code'] == 200) $specificationsArr = $specificationsInfo['data'];
            //评价
            $evaluateArr = [];
            $evaluateInfo = controller('erp/Evaluatelogic', 'logic') -> getListByGoodsid($goods_id);//dump($evaluateInfo);
            if($evaluateInfo['code'] == 200) $evaluateArr = $evaluateInfo['data'];
            //dump($rel_info);die;
            //商品sku 列表
            $skuListArr = [];
            $skuinfo = controller('erp/GoodsSkulogic', 'logic') ->goods_sku_list($user_id = 0, $store_id, $goods_id);//dump($skuinfo);
            if($skuinfo['code'] == 200) $skuListArr = $skuinfo['data']['data'];
            
            //价格 取出
            //先  取出 门店对应的仓库 id
            $warehouse_list = model('erp/ErpStoreWarehouse') -> getStoreWarehouse($store_id);
            foreach ($warehouse_list['data'] as $key => $value) {
                if($value['type'] == 1){//分店仓库
                    $store_warehouse_list[] = $value['wid'];
                }
            }
            
            $map = [];
            $map[] = ['goods_id', '=', $goods_id];
            if(isset($store_warehouse_list)) $map[] = ['warehouse_id', 'in', $store_warehouse_list];
            $rel_price = model('erp/ErpGoodsWarehouseStockNum') -> where($map) -> min('price');//dump($rel_price);
            if($rel_price <= 0){
                $map = [];
                $map[] = ['goods_id', '=', $goods_id];
                $map[] = ['price', '>', 0];
                $rel_price = model('erp/ErpGoodsSku') -> where($map) -> min('price');//dump($rel_price);
            }//如果本地仓库存没有货 那么价格可能就是空 用标准价格显示

            //商品状态
            $goods_status = 2;
            $map = [];
            $map[] = ['goods_id', '=', $goods_id];
            $map[] = ['sku_status', '=', 1];//如果有可售的
            $is_status = model('erp/ErpGoodsSku') -> where($map) -> find();//dump($rel_price);
            if($is_status) $goods_status = 1;

            //商品分类数据
            $class_arr = [];
            $map = [];
            $map[] = ['goods_id', '=', $goods_id];
            $class_list = model('erp/ErpGoodsClassGl')-> where($map) -> select();
            foreach ($class_list as $key => $value) {
                if(!isset($value ->get_erp_goods_class -> title)) continue;
                $class_arr[] = [
                    'class_id'   => $value['class_id'],
                    'class_name' => $value ->get_erp_goods_class -> title,
                ];
            }
            //dump($coverlistimgArr);
            $rel_info = [
                'goodsId'                  => (int)$info['id'],
                'goodsName'                => (string)$info['goods_name'],
                'goodsCode'                => (string)$info['goods_code'],
                'unitMeasurement'          => (string)$info['unit_measurement'],
                'goodsClasstempid'         => (int)$info['goods_classtempid'],
                'coverImgArr'              => (array)$coverlistimgArr,
                'parameterArr'             => (array)$parameterArr,
                'specificationsArr'        => (array)$specificationsArr,
                'isSingleSpecification'    => (int)$info['is_single_specification'],
                'supplierInfo'             => isset($info->get_erp_supplier) ? $info->get_erp_supplier->toArray() : (object)[],
                'brandInfo'                => isset($info->get_erp_goods_brand) ? $info->get_erp_goods_brand->toArray() : (object)[],
                'evaluateArr'              => (array)$evaluateArr,
                'price'                    => (string)sprintf("%.2f",$rel_price),
                'goodsStatus'              => $goods_status,
                'classArr'                 => $class_arr,
                'detailsImgArr'            => (array)$detailsImgArr,
                'skuListArr'               => (array)$skuListArr,
                //分类 和 状态
            ];
            //dump($rel_info);die;
            //dump($rel_list);
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                // DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $rel_info);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }

	/**
     * 添加
     * @param  int    $user_id   操作用户ID
     * @param  string    $goods_name  	 商品名称
     * @param  string    $goods_code  	 商品编码
     * @param  int       $brand_id  	 品牌id
     * @param  int       $supplier_id  	 供应商id
     * @param  array     $goods_classid  商品分类id
     * @param  int       $supplier_id  	 供应商id
     * @param  array     $cover_video_arr 商品封面缩略图
     * @param  string    $unit_measurement  	 计量单位
     * @param  array     $parameter 参数
     * @param  array     $single_item 单品参数
     * @param  int       $is_single_specification  	 是否多规格0 否 1是
     * @author jason
     * @return mixed
     */
    public function goods_add($user_id, $goods_name, $goods_code, $brand_id, $supplier_id, $goods_classid, $cover_video_arr, $unit_measurement, $parameter, $single_item, $is_single_specification, $specifications, $details_arr, $goods_classtempid){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' 	            => $user_id,
				'goods_name' 		    => $goods_name,
				'goods_code' 	        => $goods_code,
				'brand_id' 		        => $brand_id,
				'supplier_id' 		    => $supplier_id,
                'goods_classid'         => $goods_classid,
                'cover_video_arr'       => $cover_video_arr,
                'unit_measurement'      => $unit_measurement,
                'parameter'             => $parameter,
                'single_item'           => $single_item,
                'specifications'        => $specifications,
                'details_arr'           => $details_arr,
                'goods_classtempid'           => $goods_classtempid,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            //添加产品表
            $rel = model('ErpGoods') -> addData($goods_name, $goods_code, $supplier_id, $brand_id, $unit_measurement, $is_single_specification, $user_id, $goods_classtempid);
            if($rel['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error1');//后置错误 -1003
            }
            $goods_id = $rel['data'];
         
            //添加产品缩略图表
            $cover_arr = [];
            foreach ($cover_video_arr as $key => $value) {
                $cover_arr[] = [
                    'goods_id'       => $goods_id,
                    'img_id'         => $value,
                ];
            }
            $rel = model('ErpGoodsCoverimg') -> saveAll($cover_arr);//dump($rel);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error2');//后置错误 -1003
            }
            
            //添加产品详情图表
            $cover_arr = [];
            foreach ($details_arr as $key => $value) {
                $cover_arr[] = [
                    'goods_id'       => $goods_id,
                    'img_id'         => $value,
                ];
            }
            $rel = model('ErpGoodsDetails') -> saveAll($cover_arr);//dump($rel);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error2');//后置错误 -1003
            }
            //dump($goods_classid);
            //产品分类
            foreach ($goods_classid as $key => $value) {
                $goods_classidr_arr[] = [
                    'goods_id'       => $goods_id,
                    'class_id'    => $value,
                ];
            }
            $rel = model('ErpGoodsClassGl') -> saveAll($goods_classidr_arr);//dump($rel);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error3');//后置错误 -1003
            }
            //产品参数
            $parameter_arr = [];
            foreach ($parameter as $key => $value) {
                $parameter_arr[] = [
                    'goods_id'       => $goods_id,
                    'parameter_id'    => $value['parameter_id'],
                    'attribute_id'    => $value['attribute_id'],
                ];
            }
            $rel = model('ErpGoodsParameter') -> saveAll($parameter_arr);//dump($rel);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error4');//后置错误 -1003
            }
    
            //产品规格
            $specifications_arr = [];
            $s_attribute_arr = [];
            foreach ($specifications as $key => $value) {
                $specifications_arr[] = [
                    'goods_id'                => $goods_id,
                    'specifications_id'       => $value['specifications_id'],
                    'specifications_title'    => $value['specifications_title'],
                ];

                foreach ($value['attribute'] as $key1 => $value1) {
                    $s_attribute_arr[] = [
                        'goods_id'          => $goods_id,
                        'specifications_id' => $value['specifications_id'],
                        'attribute_id'      => $value1['attribute_id'],
                        'attribute_title'   => $value1['attribute_title'],
                    ];
                }
            }
            $rel = model('ErpGoodsSpecifications') -> saveAll($specifications_arr);//dump($rel);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error5');//后置错误 -1003
            }
            $rel = model('ErpGoodsSpecificationsAttribute') -> saveAll($s_attribute_arr);//dump($rel);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error6');//后置错误 -1003
            }

            //单品参数 single_item
            $specifications= [];
            foreach ($single_item as $key => $value) {
                //规格数量
                $specifications[] = [
                    'goods_id'                            => $goods_id,
                    'goods_name'                          => $goods_name,
                    'goods_specifications'                => $value['goods_specifications'],
                    //'specifications1_id'                => $value['specifications1_id'],
                    //'specifications2_id'                => $value['specifications2_id'],
                    'specifications1_attribute_id'      => $value['specifications1_attribute_id'],
                    'specifications2_attribute_id'      => $value['specifications2_attribute_id'],
                    'article_no'                        => $value['article_no'],
                    'weight'                            => $value['weight'],
                    'volume'                            => $value['volume'],
                    'price'                             => $value['price'],
                    'purchase_price'                    => $value['purchase_price'],
                    'sku_status'                        => $value['sku_status'],
                ];  
            }//dump($specifications);
            $rel = model('ErpGoodsSku') -> saveAll($specifications);//dump($rel);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error7');//后置错误 -1003
            }
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }

    /**
     * 编辑
     * @param  int    $user_id   操作用户ID
     * @param  string    $goods_name  	 商品名称
     * @param  string    $goods_code  	 商品编码
     * @param  int       $brand_id  	 品牌id
     * @param  int       $supplier_id  	 供应商id
     * @param  array     $goods_classid  商品分类id
     * @param  int       $supplier_id  	 供应商id
     * @param  array     $cover_video_arr 商品封面缩略图
     * @param  string    $unit_measurement  	 计量单位
     * @param  array     $parameter 参数
     * @param  array     $single_item 单品参数
     * @param  int       $is_single_specification  	 是否多规格0 否 1是
     * @author jason
     * @return mixed
     */
    public function goods_edit($goods_id, $user_id, $goods_name, $goods_code, $brand_id, $supplier_id, $goods_classid, $cover_video_arr, $unit_measurement, $parameter, $single_item, $is_single_specification, $specifications, $details_arr, $goods_classtempid){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'goods_id' 	            => $goods_id,
				'user_id' 	            => $user_id,
				'goods_name' 		    => $goods_name,
				'goods_code' 	        => $goods_code,
				'brand_id' 		        => $brand_id,
				'supplier_id' 		    => $supplier_id,
                'goods_classid'         => $goods_classid,
                'cover_video_arr'       => $cover_video_arr,
                'unit_measurement'      => $unit_measurement,
                'parameter'             => $parameter,
                'single_item'           => $single_item,
                'specifications'        => $specifications,
                'details_arr'           => $details_arr,
                'goods_classtempid'     => $goods_classtempid,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            //添加产品表
            $map = [];
            $map['id'] = $goods_id;
            $data = [];
            $data['goods_name']                 = $goods_name;
            $data['goods_code']                 = $goods_code;
            $data['supplier_id']                = $supplier_id;
            $data['brand_id']                   = $brand_id;
            $data['unit_measurement']           = $unit_measurement;
            $data['is_single_specification']    = $is_single_specification;
            $data['user_id']                    = $user_id;
            $data['goods_classtempid']          = $goods_classtempid;
            $rel = model('ErpGoods') -> save($data, $map);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error1');//后置错误 -1003
            }
            
            //添加产品缩略图表
            //删除原缩略图
            $map = [];
            $map['goods_id'] = $goods_id;
            $rel = model('ErpGoodsCoverimg') -> where($map) -> delete();
            foreach ($cover_video_arr as $key => $value) {
                $cover_arr[] = [
                    'goods_id'       => $goods_id,
                    'img_id'         => $value,
                ];
            }
            $rel = model('ErpGoodsCoverimg') -> saveAll($cover_arr);//dump($rel);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error2');//后置错误 -1003
            }
           
            //添加产品详情图表
            //删除
            $map = [];
            $map['goods_id'] = $goods_id;
            $rel = model('ErpGoodsDetails') -> where($map) -> delete();

            $cover_arr = [];
            foreach ($details_arr as $key => $value) {
                $cover_arr[] = [
                    'goods_id'       => $goods_id,
                    'img_id'         => $value,
                ];
            }
            $rel = model('ErpGoodsDetails') -> saveAll($cover_arr);//dump($rel);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error2');//后置错误 -1003
            }

            //产品分类
            //删除
            $map = [];
            $map['goods_id'] = $goods_id;
            $rel = model('ErpGoodsClassGl') -> where($map) -> delete();
            foreach ($goods_classid as $key => $value) {
                $goods_classidr_arr[] = [
                    'goods_id'       => $goods_id,
                    'class_id'       => $value,
                ];
            }
            $rel = model('ErpGoodsClassGl') -> saveAll($goods_classidr_arr);//dump($rel);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error3');//后置错误 -1003
            }
            //产品参数
            //删除
            $map = [];
            $map['goods_id'] = $goods_id;
            $rel = model('ErpGoodsParameter') -> where($map) -> delete();
			
			$parameter_arr = [];
			foreach ($parameter as $key => $value) {
				$parameter_arr[] = [
					'goods_id'       => $goods_id,
					'parameter_id'    => $value['parameter_id'],
					'attribute_id'    => $value['attribute_id'],
				];
			}

			$rel = model('ErpGoodsParameter') -> saveAll($parameter_arr);//dump($rel);
			if(!$rel){
				DB::rollback();
				return array_out(-1005, 'error4');//后置错误 -1003
			}

            //产品规格
            //删除
			if(!empty($specifications)){
				$map = [];
				$map['goods_id'] = $goods_id;
				$rel = model('ErpGoodsSpecifications') -> where($map) -> delete();
				//删除
				$map = [];
				$map['goods_id'] = $goods_id;
				$rel = model('ErpGoodsSpecificationsAttribute') -> where($map) -> delete();

				$specifications_arr = [];
				$s_attribute_arr = [];
				foreach ($specifications as $key => $value) {
					$specifications_arr[] = [
						'goods_id'                => $goods_id,
						'specifications_id'       => $value['specifications_id'],
						'specifications_title'    => $value['specifications_title'],
					];

					foreach ($value['attribute'] as $key1 => $value1) {
						$s_attribute_arr[] = [
							'goods_id'          => $goods_id,
							'specifications_id' => $value['specifications_id'],
							'attribute_id'      => $value1['attribute_id'],
							'attribute_title'   => $value1['attribute_title'],
						];
					}
				}
				$rel = model('ErpGoodsSpecifications') -> saveAll($specifications_arr);//dump($rel);
				if(!$rel){
					DB::rollback();
					return array_out(-1005, 'error5');//后置错误 -1003
				}
				$rel = model('ErpGoodsSpecificationsAttribute') -> saveAll($s_attribute_arr);//dump($rel);
				if(!$rel){
					DB::rollback();
					return array_out(-1005, 'error6');//后置错误 -1003
				}
			}
           
			if(!empty($single_item)){
				//单品参数 single_item
				//删除
				$map = [];
				$map['goods_id'] = $goods_id;
				$rel = model('ErpGoodsSku') -> where($map) -> delete();

				$specifications= [];
				foreach ($single_item as $key => $value) {
					//规格数量
					$specifications[] = [
						'goods_id'                            => $goods_id,
						'goods_name'                          => $goods_name,
						'goods_specifications'                => $value['goods_specifications'],
						//'specifications1_id'                => $value['specifications1_id'],
						//'specifications2_id'                => $value['specifications2_id'],
						'specifications1_attribute_id'      => $value['specifications1_attribute_id'],
						'specifications2_attribute_id'      => $value['specifications2_attribute_id'],
						'article_no'                        => $value['article_no'],
						'weight'                            => $value['weight'],
						'volume'                            => $value['volume'],
						'price'                             => $value['price'],
						'sku_status'                        => $value['sku_status'],
					];  
				}//dump($specifications);
				$rel = model('ErpGoodsSku') -> saveAll($specifications);//dump($rel);
				if(!$rel){
					DB::rollback();
					return array_out(-1005, 'error7');//后置错误 -1003
				}
			}
            
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }

    /**
     * 删除
     * @param  int    $user_id   操作用户ID
     * @author jason
     * @return mixed
     */
    public function goods_delete($goods_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'goods_id' 	            => $goods_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $map = [];
            $map['id'] = $goods_id;
            $rel = model('ErpGoods') -> where($map) -> setField('goods_status', 1);
            
            //sku_id也得删除
            $map = [];
            $map['goods_id'] = $goods_id;
            $rel = model('ErpGoodsSku') -> where($map) -> setField('sku_status', 2);//dump($rel);
            if(!$rel){
                DB::rollback();
                return array_out(-1005, 'error');//前置错误 -1002
            }
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
}